var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r = t("GlobalUserData"),
s = t("HallConstant"),
l = t("HallVitView"),
c = t("BroadCastMessage"),
d = t("Util"),
h = t("ChampionManager"),
p = cc._decorator,
u = p.ccclass,
f = p.property,
m = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_vit = null,
        e.lab_vit = null,
        e.lab_time = null,
        e.icon_vit = null,
        e._hallControl = null,
        e.prevVitNum = 0,
        e.nIntervalHandle = 0,
        e
    }
    return n(e, t),
    e.prototype.onDestroy = function() {
        clearInterval(this.nIntervalHandle)
    },
    e.prototype.init = function(t) {
        this._hallControl = t,
        this.onSetOwnVit(),
        this.lab_time.node.active = !1,
        r.default.vitData.num < this.getVitMax() ? (this.lab_time.node.active = !0, this.onSetTime()) : this.lab_time.node.active = !1
    },
    e.prototype.getVitMax = function() {
        return s.Vit_Init_Num + h.default.Ins.getGradeBuff(r.default.nTrophy, null).vitBuff
    },
    e.prototype.onSetOwnVit = function(t) {
        var e = this;
        t ? d.Util.AnimNumJump(this.lab_vit.node, this.prevVitNum, r.default.vitData.num,
        function(t) {
            e.lab_vit.string = t + "/ " + e.getVitMax()
        },
        function() {
            e.lab_vit.string = r.default.vitData.num + "/" + e.getVitMax(),
            e.prevVitNum = r.default.vitData.num
        },
        this.icon_vit) : (this.lab_vit.string = r.default.vitData.num + "/" + this.getVitMax(), this.prevVitNum = r.default.vitData.num)
    },
    e.prototype.updateVitNum = function() {
        var t = this,
        e = this.getVitMax() - r.default.vitData.num,
        o = function() {
            var i = new Date().getTime() - r.default.vitData.time,
            n = Math.floor(i / 12e4);
            if (n >= e) return r.default.saveVitData(!0, e),
            void t.unschedule(o);
            r.default.saveVitData(!0, n)
        };
        this.schedule(o, 1)
    },
    e.prototype.onSetTime = function() {
        var t = this,
        e = function() {
            r.default.vitData.num >= t.getVitMax() ? (t.lab_time.node.active = !1, clearInterval(t.nIntervalHandle)) : t.lab_time.node.active = !0;
            var e = r.default.vitData.time + 12e4,
            o = new Date().getTime(),
            i = Math.floor((e - o) / 1e3),
            n = Math.floor(i / 60);
            t.lab_time.string = n + ":" + (i - 60 * n),
            i <= 0 && (r.default.saveVitData(!0, 1), t.onSetOwnVit())
        },
        o = this.getVitMax() - r.default.vitData.num,
        i = new Date().getTime() - r.default.vitData.time,
        n = Math.floor(i / 12e4);
        if (n >= o) return r.default.saveVitData(!0, o),
        void this.onSetOwnVit();
        r.default.saveVitData(!0, n),
        this.onSetOwnVit(),
        this.nIntervalHandle = setInterval(e, 1e3),
        e()
    },
    e.prototype.onBtnAdd = function() {
        this.playAudio(s.Audio_ID.btn_click);
        var t = cc.instantiate(this.pfb_vit);
        this._hallControl.node.addChild(t, 99),
        t.getComponent(l.default).init(this)
    },
    e.prototype.playAudio = function(t) {
        this._hallControl ? this._hallControl.playAudio(t) : c.default.getInstance().SendMessage(s.Broadcast_Func.Audio, t)
    },
    a([f(cc.Prefab)], e.prototype, "pfb_vit", void 0),
    a([f(cc.Label)], e.prototype, "lab_vit", void 0),
    a([f(cc.Label)], e.prototype, "lab_time", void 0),
    a([f(cc.Node)], e.prototype, "icon_vit", void 0),
    a([u], e)
} (cc.Component);
o.default = m